using imitateMacQQ.WebApi.Configures;
using imitateMacQQ.WebApi.Domain.utils;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace imitateMacQQ.WebApi.Api;

[ApiController]
[Route("api/[controller]/[action]")]
public class UploadImageFilesController : ControllerBase
{
    private readonly IUploadService _uploadService;

    public UploadImageFilesController(IUploadService uploadService, INLogHelper logHelper)
    {
        _uploadService = uploadService;
        _logHelper = logHelper;
    }

    private readonly INLogHelper _logHelper;

    [HttpPost]
    [Route("api/suf")]
    public async Task<bool> Upload([FromHeader] string account, [FromHeader] string path)
    {
        try
        {
            var files = Request.Form.Files;
            var result = await _uploadService.UploadFile(files, account, path); //图片上传
            if (!result)
                throw new Exception("Web Transfer File-Data Bad");
            return true;
        }
        catch (Exception ex)
        {
            _logHelper.LogError(ex);
            return false;
        }
    }
}